package reflect;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Scanner;

public class ReflectDemo1 {
    public static void main(String[] args) throws ClassNotFoundException {
        //获取String的类对象
//        Class<ArrayList> cls = ArrayList.class;
        //通过类对象反映出其表示的类的完全限定名
//        Class cls ;
//        try {
//            cls = Class.forName("java.lang.String");
//        } catch (ClassNotFoundException e) {
//            throw new RuntimeException(e);
//        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入类名:");
        String className = scanner.nextLine();
        Class cls = Class.forName(className);
        //获取全限定名
        String name = cls.getName();
        System.out.println(name);
        //仅获取类名
        name = cls.getSimpleName();
        System.out.println(name);

        //获取信息
        Package pack = cls.getPackage();
        System.out.println(pack.getName());

        Method[] methods = cls.getMethods();
        System.out.println(methods.length);
        for (Method method : methods) {
            System.out.println(method.getName());
        }

    }
}
